#import <Foundation/Foundation.h>
#import "JokeModel.h"
#import "JokeManager.h"
#import "JokePageCell.h"
#import "HPGrowingTextView.h"
#import "BaseUIViewController.h"
#import "MWPhotoBrowser.h"

#import "SDWebImageDecoder.h"
#import "SDWebImageManager.h"

@class JPCLikeStateBase;
@class JPCLikeStateLoading;
@class JPCLikeStateDisable;
@class JPCLikeStateEnable;
@class JPCUserStateBase;
@class JPCUserStateLogin;
@class JPCUserStateLogout;
@protocol JokePageCellDelegate;

@interface JokePageCell : UIView <UIWebViewDelegate,UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate,SDWebImageManagerDelegate, SDWebImageDecoderDelegate> {
    IBOutlet UIView         *jokeView;
    UIWebView               *jokeText;
    IBOutlet UIImageView    *jokeImg;
    IBOutlet UIView         *jokeWebViewContainer;
    IBOutlet UIWebView      *jokeWebView;
    IBOutlet UILabel        *userName;
    IBOutlet UITableView    *replyTable;
    IBOutlet UIImageView    *jokeViewBg;
    IBOutlet UIView         *jokeReplyView;
    IBOutlet UIImageView    *jokeReplyViewBg;
    IBOutlet UILabel        *jokeReplyCount;
    IBOutlet UIImageView    *indicator;
//    IBOutlet UIButton       *jokeImgBtn;
    IBOutlet UIView         *gap;
    NSMutableArray          *browserPhotos;
    
    NSString                *jokeUrlForMd5;
}
@property (nonatomic, retain) NSArray *scanPhotos;
@property (retain, nonatomic) JokeModel                     *jokePlaying;
@property (retain, nonatomic) JokeManager                   *jokeManagerPlaying;
//@property (retain, nonatomic) IBOutlet BaseUIScrollView     *mainView;
@property (retain, nonatomic) IBOutlet UIScrollView         *mainView;
@property (retain, nonatomic) IBOutlet UIView               *jokeInfoView;
@property (retain, nonatomic) IBOutlet UIImageView          *funnyBtn;
@property (retain, nonatomic) IBOutlet UIImageView          *unfunnyBtn;
@property (retain, nonatomic) IBOutlet UILabel              *funnyNum;
@property (retain, nonatomic) IBOutlet UILabel              *unfunnyNum;
@property (retain, nonatomic) JPCLikeStateLoading           *likeStateLoading;
@property (retain, nonatomic) JPCLikeStateEnable            *likeStateEnable;
@property (retain, nonatomic) JPCLikeStateDisable           *likeStateDisable;
@property (assign, nonatomic) JPCLikeStateBase              *currentLikeState;
@property (retain, nonatomic) JPCUserStateLogin             *userStateLogin;
@property (retain, nonatomic) JPCUserStateLogout            *userStateLogout;
@property (assign, nonatomic) JPCUserStateBase              *currentUserState;
@property (assign, nonatomic) BaseUIViewController<JokePageCellDelegate> *owner;

- (void)setData:(BaseUIViewController<JokePageCellDelegate> *)pOwner :(JokeModel *)pJoke :(JokeManager *)pJokeManager;
- (void)setMoreData;
- (void)refreshNum:(int)funny :(int)unfunny :(int)reply;
- (void)toTop;
- (void)reply;
- (IBAction)pressUnfunnyBtn:(id)sender;
- (IBAction)pressFunnyBtn:(id)sender;
//- (IBAction)scanPhoto:(id)sender;
- (void)setLikeState:(JPCLikeStateBase *)newState;
- (void)setUserState:(JPCUserStateBase *)newState;
@end

@protocol JokePageCellDelegate<NSObject>
- (void)JPCscanPhotos;  //图片浏览
- (void)JPCup;          //往上滚
- (void)JPCdown;        //往下滚
- (void)JPClogin;       //登录
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
@optional
@end

typedef enum {
    ScrollDirectionNone,
    ScrollDirectionRight,
    ScrollDirectionLeft,
    ScrollDirectionUp,
    ScrollDirectionDown,
    ScrollDirectionCrazy,
} ScrollDirection;

#pragma mark ---------顶和踩的状态机--------
@protocol JPCLikeStateDelegate<NSObject>
@optional
-(void)JPCLSstart;
-(void)JPCLSlike;
-(void)JPCLSunlike;
@end

@interface JPCLikeStateBase : NSObject<JPCLikeStateDelegate>
{
    JokePageCell        *owner;
}
-(id)init:(JokePageCell *)powner;
@end

@interface JPCLikeStateLoading : JPCLikeStateBase
@end

@interface JPCLikeStateEnable : JPCLikeStateBase
@end

@interface JPCLikeStateDisable : JPCLikeStateBase
@end

#pragma mark ---------用户是否登录的状态机-----
@protocol JPCUserStateDelegate<NSObject>
@optional
-(void)JPCUSlike;
-(void)JPCUSunlike;
@end

@interface JPCUserStateBase : NSObject<JPCUserStateDelegate>
{
    JokePageCell       *owner;
}
-(id)init:(JokePageCell *)pOwner;
@end

@interface JPCUserStateLogin : JPCUserStateBase
@end

@interface JPCUserStateLogout : JPCUserStateBase
@end